package cn.tiansu.eway.kylinengine.manager;

import org.apache.log4j.Logger;

import cn.tiansu.eway.kafka.ijava.TSMessageQueue;
import cn.tiansu.eway.kylinengine.service.KYLINEngineService;

import com.alibaba.fastjson.JSONObject;

/**
 * 多线程查询
 * 
 * @Title: QueryThread.java
 * @Description: TODO
 * @author: 吴鹏
 * @date: 2015年9月2日
 * 
 *
 */
public class MessageThread implements Runnable
{
	private final static Logger log = Logger.getLogger(MessageThread.class);
	
	/**
	 * olap和kylin的交互模块
	 */
	private KYLINEngineService kylinService = null;

	/**
	 * 接收消息
	 */
	private String message = null;
	
	private TSMessageQueue teQueue = null;

	public MessageThread(String message, KYLINEngineService kylinService,TSMessageQueue teQueue)
	{
		this.message = message;
		this.kylinService = kylinService;
		this.teQueue = teQueue;
	}

	@Override
	public void run()
	{
		if (message.indexOf("olaps") > -1)
		{
			JSONObject result = kylinService.queryDataByCondition(message);
			String res = teQueue.responseMsg(message, 0, result);
			log.info("answer msg is :" + res);
		}
		else if (message.indexOf("msg") > -1)
		{
			kylinService.updateTenant(message);
		} 
	}

}
